﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data;
using MySql.Data.MySqlClient;

namespace LibFriesland_Campina_CRM
{
    class DalNA
    {
        //Lay danh sach tat ca NA
        public static List<BizNA> getAll()
        {
            Friesland_Campina_CRM_DataContext db = new Friesland_Campina_CRM_DataContext(new MySqlConnection(Thuvien.getConnString()));
            try
            {
                var nas = from item in db.NA
                          where item.NACharID !="NADEFAULT" && item.NACharID !="natest"
                          select new BizNA(item.NACharID, item.Name);
                return nas.ToList();
            }
            catch(Exception ex)
            {
                return null;
            }
        }

        //Lay thong tin NA
        public static BizNA getNAbyID(string pNa_charid)
        {
            Friesland_Campina_CRM_DataContext db = new Friesland_Campina_CRM_DataContext(new MySqlConnection(Thuvien.getConnString()));
            try
            {
                var na = db.NA.Single(p => p.NACharID == pNa_charid);
                return new BizNA(na.NACharID, na.Name);
            }
            catch
            {
                return null;
            }
        }

        //Lay sup_charid cua Sup quan ly NA
        public static string getSupIDbyNA(string pNa_charid)
        {
            Friesland_Campina_CRM_DataContext db = new Friesland_Campina_CRM_DataContext(new MySqlConnection(Thuvien.getConnString()));
            try
            {
                var na = db.NA.Single(p => p.NACharID == pNa_charid);
                return na.BySup;
            }
            catch(Exception ex)
            {
                return "";
            }
        }
    }
}
